package com.briup.mt.service.impl;

import com.briup.mt.bean.Greenhouse;
import com.briup.mt.bean.GreenhouseExample;
import com.briup.mt.dao.GreenhouseMapper;
import com.briup.mt.service.IGreenHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class GreenHouseImpl implements IGreenHouseService {
    @Autowired
    private GreenhouseMapper greenhouseMapper;

    @Override
    public List<Greenhouse> query(String name, String status) {
        GreenhouseExample example = new GreenhouseExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }if (!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusEqualTo(status);
        }
        List<Greenhouse> list = greenhouseMapper.selectByExample(example);

        return list;
    }

    @Override
    public void saveOrUpdate(Greenhouse greenhouse) {
    if (greenhouse.getId() == null){
        greenhouseMapper.insert(greenhouse);
    }else {
        greenhouseMapper.updateByPrimaryKey(greenhouse);
    }
    }

    @Override
    public void deleteById(long id) {
        greenhouseMapper.deleteByPrimaryKey(id);
    }
}
